package com.example.barcodescanner;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

public class ProductActivity extends Activity {
	
    private String path;
    private static final int RESOURCES_VIDEO = 6;

	String link;
	String productCode1;
	String videoLink;
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_product);
        link = getIntent().getExtras().getString("link");
        videoLink = getIntent().getExtras().getString("videoLink");
        System.out.println(link);
        link = "http://adtouch.cloudfoundry.com/rest/ad/barcode/" + link + "/video";
        playVideo();
    }    
    
    @SuppressLint({ "NewApi", "NewApi" })
	private void playVideo() {
                        //path = "http://commonsware.com/misc/test2.3gp";
    	
        
    	
    	try{	
                		System.out.println("link doesnot starts with http");
                		
                		VideoView videoView = (VideoView) this.findViewById(R.id.videoView1);

                		 // add controls to a MediaPlayer like play, pause.
                		 MediaController mc = new MediaController(this);
                		 videoView.setMediaController(mc);

                		 if(videoLink.contains("://"))
                		 {
                			 videoView.setVideoURI(Uri.parse(videoLink));
                		 }
                		 else{
                		 // Set the path of Video or URI
                		 videoView.setVideoURI(Uri.parse(link));
                		 //
                		 }
                		 // Set the focus
                		 videoView.requestFocus();
                		 videoView.start();
                		
                		
                		
                		//String uri = "android.resource://" + getPackageName() + "/" + R.raw.sample;
                    	//String uri = "http://adtouch.cloudfoundry.com/files/ad/" + link;
                    	//System.out.println(uri);
                    	//MediaController mc = (MediaController) findViewById(R.id.mediaController1);
                    	//mMediaPlayer.se))
                    	//mMediaPlayer.setDataSource(uri);
                    // Create a new media player and set the listeners
                    
                    	
                }
                catch(Exception e)
                {
                	e.printStackTrace();
                }
    }

}
